﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.Serialization;
using System.Globalization;
using System.Drawing;

namespace Core.Alphabet
{
	[Serializable]
	public class Settings
	{
		public bool EnableLegs = false;
		//public bool RandomOrder = true;
		//public bool RandomPosition = false;
		//public bool RandomFont = false;
		//public bool RandomColor = false;
		public Color FontColor = Color.Black;
		public Font FontStyle = new Font(FontFamily.GenericSansSerif, 20);
		public Color BackgroundColor = Color.White;

		public int IntervalMilliseconds = 1000;
				
		public string Language = "en-US";
		public string UILanguage = "en-US";
		
		public Settings()
		{
			Load(this);
		}

		public CultureInfo Culture
		{
			get
			{
				CultureInfo ci = CultureInfo.InvariantCulture;

				ci = new CultureInfo(Language);

				if (ci.IsNeutralCulture && Language != null && Language.Length > 2)
					ci = new CultureInfo(Language.Substring(0, 2));

				return ci;
			}
		}

		public CultureInfo SpecificCulture
		{
			get
			{
				CultureInfo ci = CultureInfo.InvariantCulture;

				if (Language != null)
					ci = new CultureInfo(Language);

				if (ci.IsNeutralCulture)
					ci = CultureInfo.CreateSpecificCulture(ci.Name);
				return ci;
			}
		}


		public void Save()
		{
			Stream s = File.Open("temp.dat", FileMode.Create);
			BinaryFormatter b = new BinaryFormatter();
			b.Serialize(s, this);
			s.Close();
		}

		public void Load(Settings settings)
		{
			if (!File.Exists("temp.dat"))
				return;
			Stream s = File.Open("temp.dat", FileMode.Open);
			BinaryFormatter b = new BinaryFormatter();
			try
			{
				settings = (Settings)b.Deserialize(s);
			}
			catch (SerializationException)
			{ }
			catch (TypeInitializationException)
			{ }
			s.Close();
		}
	}
}